'''
自动管理Cookoe的机制：创建一个session = requests.session(),自动维护Cookie信息
'''

import requests
s= requests.session() # 创建session
print("登录之前的cookie信息：",s.cookies)

#百格登录的接口
url = "https://www.bagevent.com/user/login"
cs ={"access_type":1,
     "loginType": 1,
     "emailLoginWay":0,
     "account":"2780487875@qq.com",
     "password": "qq2780487875",
     "remindmeBox": "on",
     "remindme":1
}
r = s.post(url,data=cs) # 用session发送请求
print(r.text)
assert "<title>百格活动 - 账户总览</title>" in r.text
print("登录之后的cookie信息：",s.cookies)

print("*"*50)
# 百格查询的接口
url = "https://www.bagevent.com/account/dashboard"
r = s.get(url)
# print(r.text)
assert "<title>百格活动 - 账户总览</title>"in r.text
# 退出登录
url = "https://www.bagevent.com/user/login_out"
r = s.get(url)
print("退出登录之后的cookie信息：",s.cookies)

ts = requests.utils.dict_from_cookiejar(s.cookies)
print(ts)
for k,v in ts.items(): # 遍历字典
    print(k,":",v)